home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / BUTTON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  5.3 KB  |  217 lines

  1. /********************************************
  2.     file: button.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1996: C. Moreau: 
  8.     comments: 
  9. *********************************************/
  10.  
  11. /********************************************
  12.     includes
  13. *********************************************/
  14. #ifdef __PUREC__ 
  15. #include <aes.h>
  16. #include <tos.h>
  17. #include <vdi.h>
  18. #include <compend.h>
  19. #else
  20. #include <aesbind.h>
  21. #include <osbind.h>
  22. #include <vdibind.h>
  23. #endif
  24.  
  25. #include <ctype.h>
  26. #include <stddef.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. #include "e:\proging\c\libs\malib\alert.h"
  32. #include "button.h"
  33. #include "cursor.h"
  34. #include "dialog.h"
  35. #include "edit.h"
  36. #include "init.h"
  37. #include "keys.h"
  38. #include "menu.h"
  39. #include "send.h"
  40. #include "wind.h"
  41.  
  42. #include "bfed_rsc.h"
  43.  
  44. /********************************************
  45.     defines
  46. *********************************************/
  47.  
  48. /********************************************
  49.     locals vars declarations & definitions
  50. *********************************************/
  51.  
  52. /********************************************
  53.     globals vars declarations
  54. *********************************************/
  55.  
  56. /********************************************
  57.     locals functions declarations
  58. *********************************************/
  59. static long calc_pos(int mousex, int mousey);
  60.  
  61. /********************************************
  62.     globals functions definitions
  63. *********************************************/
  64. /*
  65.     name: do_button
  66.     utility: 
  67.     comment: 
  68.     parameters: 
  69.         int mousex: x position of the mouse
  70.         int mousey: y ...
  71.     return: none
  72.     date: 1989
  73.     author: Jim Charlton
  74.     modifications:
  75.         1995: C. Moreau: 
  76. */
  77. void do_button(int mousex, int mousey)
  78. {    
  79.     if (!thefrontwin->form)
  80.     {
  81.         int x,y;
  82.         int status = LEFT_BUTTON;    /* mouse button state */
  83.         int lastw = 0, lasth = 0;
  84.         long newpos;    /* new position of the cursor */
  85.  
  86.         do
  87.         {
  88.             vq_mouse(thefrontwin->graf.handle, &status, &x, &y);
  89.             if ( (abs(x-mousex)) > 6 || (abs(y-mousey)) > 6 )
  90.                 graf_rubberbox(mousex, mousey, 6, 6, &lastw, &lasth);
  91.         } while(status == LEFT_BUTTON);
  92.  
  93.         newpos = calc_pos(mousex, mousey);
  94.         if (newpos != -1L)    /* not outside window */
  95.         {
  96.             if (newpos == -2L)    /* try to go out file */
  97.             {
  98.                 thefrontwin->position = thefrontwin->flen-1;
  99.                 check_scroll(thefrontwin);        
  100.             }
  101.             else
  102.             {        /* if some byte selected by mouse */
  103.                 if (lastw > 7 || lasth > 7)
  104.                 {
  105.                     thefrontwin->startmark = newpos;
  106.                     newpos = calc_pos(x-3, y-3);
  107.                     if (newpos != -1L)
  108.                     {
  109.                         thefrontwin->endmark =                                 \
  110.                                 (newpos<thefrontwin->flen-1) ?                 \
  111.                                     newpos : (thefrontwin->flen-2);
  112.                         thefrontwin->position = thefrontwin->endmark;
  113.                         if (thefrontwin->startmark <= thefrontwin->endmark) /* it must !! */
  114.                         {
  115.                             send_redraw(thefrontwin);
  116.                             thefrontwin->markson = TRUE;
  117.                             update_menu();
  118.                         }
  119.                         thefrontwin->position = newpos;
  120.                     }
  121.                 }
  122.                 else
  123.                     thefrontwin->position = newpos;                
  124.             }
  125.             window_info(thefrontwin);
  126.         }
  127.     }
  128.     else        /* if someone as clicked in a form */
  129.     {
  130.         if (thefrontwin->form == dsearch)    /* Find dialog */
  131.             dialog_search_exec();
  132.         else if (thefrontwin->form == ddisk)
  133.             dialog_disk_exec();
  134.         else if (thefrontwin->form == dprint)
  135.             dialog_print_exec();
  136.         else if (thefrontwin->form == dpos)
  137.             dialog_pos_exec();
  138.     }
  139. }
  140.  
  141. /********************************************
  142.     locals functions definitions
  143. *********************************************/
  144. /*
  145.     name: calc_pos
  146.     utility: 
  147.     comment: 
  148.     parameters:
  149.         int mousex: x position of the mouse
  150.         int mousey: y ...
  151.     return:
  152.         long :
  153.             position: position of the data in file
  154.             -1L: outside window or hexa input not finished
  155.             -2L: Try to move cursor outside file
  156.     date: 1989
  157.     author: Jim Charlton
  158.     modifications:
  159.         may 13 96: C. Moreau:    Go position only when clic in window
  160.         nov 14 96: C. Moreau:    Make code much readable
  161.                                         included NB_DATA_ON_LINE in code 
  162. */
  163. static long calc_pos(int mousex, int mousey)
  164. {
  165.     const int    x = thefrontwin->work.g_x,  /* window sizes */
  166.                     y = thefrontwin->work.g_y,
  167.                     w = thefrontwin->work.g_w,
  168.                     h = thefrontwin->work.g_h;
  169.  
  170.     mousex -= 5;
  171.  
  172.         /* inside window */
  173.     if (     (x <= mousex) || (mousex <= x + w)
  174.              || (y <= mousey) || (mousey <= y + h) )
  175.     {
  176.             /* mouse inside window  in ASCII part */
  177.         if( (x + gl_wchar*3*NB_DATA_IN_LINE < mousex)
  178.              && (mousex < x + gl_wchar*4*NB_DATA_IN_LINE) )
  179.         {
  180.             const int xin = (mousex - x - gl_wchar * 3*NB_DATA_IN_LINE)/gl_wchar;
  181.  
  182.             mousex = x + xoffset[xin]*gl_wchar + 1;
  183.             inhex = FALSE;
  184.         }
  185.         else /* in HEX part */
  186.             inhex = TRUE;
  187.     
  188.         {    
  189.             register int column=0;    /* column number in window */
  190.             const int line = (mousey - y)/gl_hchar; /* line number in window */
  191.             long pos;
  192.     
  193.             while ( xoffset[column]*gl_wchar < (mousex - x) )
  194.                 column++;
  195.         
  196.             pos = column + line*NB_DATA_IN_LINE + thefrontwin->topchar - 1;
  197.         
  198.             if (pos <= thefrontwin->flen-1)
  199.             {
  200.                 if (thefrontwin->icount) /* don't allow cursor move til finish entry */
  201.                 {    
  202.                     Bconout(2,7);
  203.                     rsc_alert(ENTER_HEX);
  204.                     
  205.                     return -1L;                
  206.                 }
  207.                 else
  208.                     return pos;
  209.             }
  210.             else
  211.                 return -2L; /* trying to move cursor outside file !    */                
  212.         }
  213.     }
  214.     else    /* outside window */
  215.         return -1L;
  216. }
  217.